package org.fast.develop.logicflow.runtime.convert.builder.impl;

import cn.hutool.json.JSONObject;
import lombok.Data;
import org.fast.develop.logicflow.builder.AbstractLogicFlowNodeBuilder;
import org.fast.develop.logicflow.core.meta.base.Resource;
import org.fast.develop.logicflow.core.meta.shape.line.SequenceFlow;
import org.fast.develop.logicflow.runtime.convert.builder.DesignerModelBuilder;
import org.fast.develop.logicflow.runtime.convert.designer.model.DesignerEdgeModel;

import java.util.List;
import java.util.Objects;

/**
 * @author czh
 * @version V1.0
 * @data Created on 2022-12-31 10:18
 */
@Data
public class DesignerSequenceModelBuilder implements DesignerModelBuilder<DesignerEdgeModel> {

    private final String DEFAULT_NAME = "连线";

    private DesignerEdgeModel designerModel;

    private AbstractLogicFlowNodeBuilder logicFlowBuilder;

    @Override
    public AbstractLogicFlowNodeBuilder convert() {
        return null;
    }

    @Override
    public String getType() {
        return "sequenceFlow";
    }

    @Override
    public void convert(List<JSONObject> jsonObjects, Resource resource) {
        SequenceFlow sequenceFlow = (SequenceFlow) resource;
        JSONObject sequenceObj = new JSONObject();
        sequenceObj.set("type", getType());
        sequenceObj.set("resourceId", sequenceFlow.getResourceId());
        sequenceObj.set("sourceRef", sequenceFlow.getSourceRef());
        sequenceObj.set("targetRef", sequenceFlow.getTargetRef());
        if(Objects.nonNull(sequenceFlow.getCondition()) && Objects.nonNull(sequenceFlow.getCondition().getExpression())){
            sequenceObj.set("conditionExpression", sequenceFlow.getCondition().getExpression());
        }

        jsonObjects.add(sequenceObj);
    }
}
